package com.example.app.repository;

import com.example.app.entity.Medication;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
import java.util.Optional;

@Repository
public interface MedicationRepository extends JpaRepository<Medication, Long> {

    // 根据用户 ID 查询该用户所有锻炼记录
    List<Medication> findByUserId(Long userId);

    // 根据用户 ID 和锻炼日期查询特定锻炼记录
    List<Medication> findByUserIdAndDate(Long userId, LocalDate date);
    Medication findByUserIdAndDateAndTime(Long userId, LocalDate date, LocalTime time);
    @Modifying
    @Transactional
    void deleteByUserId(Long userId);
    @Modifying
    @Transactional
    void deleteByUserIdAndDate(Long userId, LocalDate date);
    @Modifying
    @Transactional
    void deleteByUserIdAndDateAndTime(Long userId, LocalDate date, LocalTime time);
}
